package service;

import dao.ImplementUser;
import pojo.User;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/findUserServlet")
public class FindUserServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.获取id,强制类型转换
        String id = req.getParameter("id");
        ImplementUser implementUser = new ImplementUser();
        //2.调用查询方法
        User userfind = new User();
        try {
            userfind = implementUser.finduser(id);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        req.setAttribute("userfind", userfind);
        req.getRequestDispatcher("updateUser.jsp").forward(req,resp);

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
